package com.zjjk.transfer.source.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.zjjk.transfer.source.entity.SourceRecvPayOrder;
import com.zjjk.transfer.source.mapper.SourceRecvPayOrderMapper;
import com.zjjk.transfer.source.service.SourceRecvPayOrderService;
import com.zjjk.transfer.source.param.SourceRecvPayOrderPageParam;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.geekidea.springbootplus.framework.common.service.impl.BaseServiceImpl;
import io.geekidea.springbootplus.framework.core.pagination.Paging;
import io.geekidea.springbootplus.framework.core.pagination.PageInfo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.transaction.annotation.Transactional;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * 保存充值订单信息 服务实现类
 *
 * @author xuziyang
 * @since 2021-03-26
 */
@Slf4j
@Service
@DS("source")
public class SourceRecvPayOrderServiceImpl extends BaseServiceImpl<SourceRecvPayOrderMapper, SourceRecvPayOrder> implements SourceRecvPayOrderService {

    @Autowired
    private SourceRecvPayOrderMapper sourceRecvPayOrderMapper;

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean saveSourceRecvPayOrder(SourceRecvPayOrder sourceRecvPayOrder) throws Exception {
        return super.save(sourceRecvPayOrder);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean updateSourceRecvPayOrder(SourceRecvPayOrder sourceRecvPayOrder) throws Exception {
        return super.updateById(sourceRecvPayOrder);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean deleteSourceRecvPayOrder(Long id) throws Exception {
        return super.removeById(id);
    }

    @Override
    public Paging<SourceRecvPayOrder> getSourceRecvPayOrderPageList(SourceRecvPayOrderPageParam sourceRecvPayOrderPageParam) throws Exception {
        Page<SourceRecvPayOrder> page = new PageInfo<>(sourceRecvPayOrderPageParam, OrderItem.desc(getLambdaColumn(SourceRecvPayOrder::getCreateTime)));
        LambdaQueryWrapper<SourceRecvPayOrder> wrapper = new LambdaQueryWrapper<>();
        IPage<SourceRecvPayOrder> iPage = sourceRecvPayOrderMapper.selectPage(page, wrapper);
        return new Paging<SourceRecvPayOrder>(iPage);
    }

}
